package com.dys.mvpstudy.presenter;

import com.dys.mvpstudy.bean.Account;
import com.dys.mvpstudy.callback.MCallBack;
import com.dys.mvpstudy.model.MVPModel;
import com.dys.mvpstudy.mvp.view.IMVPView;

/**
 * 持有model和view的对象
 */
public class MVPPresenter {

    /**
     * 持有view的实例
     */
    private IMVPView mView;

    /**
     * 持有model的实例
     */
    private MVPModel mModel;


    /**
     * 带参构造器：用于初始化数据
     * @param mView 视图实例
     */
    public MVPPresenter(IMVPView mView) {
        this.mView = mView;
        mModel = new MVPModel();
    }

    public void getAccountData(String accountName) {
        // 告诉model,我要获取数据了
        mModel.getAccountData(accountName, new MCallBack() {
            @Override
            public void onSuccess(Account account) {
                // 成功时，展示成功的页面
                mView.showSuccessPage(account);
            }

            @Override
            public void onFailure() {
                // 失败时，展示失败的页面
                mView.showFailedPage();
            }
        });
    }
}
